import React, { FC, useEffect } from "react";
import { Form, Input } from "antd";
import { QuestionTextareaType } from "./type";

const PropsComponent: FC<QuestionTextareaType> = (props) => {
  const { placeholder, title, onchange, disabled = false } = props;
  const [form] = Form.useForm();
  //监听标题数据的变化

  useEffect(() => {
    form.setFieldsValue({ placeholder, title });
  }, [placeholder, title]);
  function handleValueChange() {
    if (onchange) {
      onchange(form.getFieldsValue());
    }
  }
  return (
    <Form layout="vertical" initialValues={{ placeholder, title }} form={form} onValuesChange={handleValueChange} disabled={disabled}>
      <Form.Item label="标题" name="title" rules={[{ required: true, message: "请输入标题" }]}>
        <Input />
      </Form.Item>
      <Form.Item label="Placeholder" name="placeholder">
        <Input />
      </Form.Item>
    </Form>
  );
};

export default PropsComponent;
